//
//  HXAppInformViewController.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/23.
//

#import "HXAppInformViewController.h"

@interface HXAppInformViewController ()
@property (nonatomic,assign) BOOL isopen;
@end

@implementation HXAppInformViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    self.fd_prefersNavigationBarHidden = YES;
    [self BottomFunction];
}
-(void)BottomFunction{
    
    UIImageView *tabr = [[UIImageView alloc] initWithFrame:CGRectMake(0, kNavHeight-44, winWidth, 44)];
    [self.view addSubview:tabr];
    UIImageView *mainscreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, winWidth, 44)];
//    appinformmid
    if([themeColors isEqualToString:@"default"]){
        mainscreen.image = [UIImage imageNamed:@"appinformmain"];
    }else{
//        mainscreen.backgroundColor = midnightRGB;
        mainscreen.image = [UIImage imageNamed:@"appinformmainhid"];
    }
//    mainscreen.image = [UIImage imageNamed:@"appinformmain"];
    [tabr addSubview:mainscreen];
    
    UIImageView *appinformlogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appinformlogo"]];
    [self.view addSubview:appinformlogo];
    [appinformlogo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tabr.mas_bottom).offset(74);
        make.width.mas_equalTo(182.33);
        make.height.mas_equalTo(181.67);
        make.centerX.mas_equalTo(self.view);
    }];
    
//VERSION: 0.0.1
    UILabel *version = [[UILabel alloc] init];
    version.text = @"VERSION: 1.0";
    version.font = [UIFont systemFontOfSize:25];
    version.textColor = [UIColor whiteColor];
    version.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:version];
    [version mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(appinformlogo.mas_bottom);
        make.centerX.mas_equalTo(self.view);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(190);
    }];
    
    UIImageView *statebj = [[UIImageView alloc] init];
    if([themeColors isEqualToString:@"default"]){
        statebj.backgroundColor = [UIColor blackColor];
    }else{
        statebj.backgroundColor = midnightRGB;
    }
    [self.view addSubview:statebj];
    [statebj mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-34);
        make.height.mas_equalTo(50);
    }];
#pragma mark 返回入口
    UIImageView *backview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
    backview.userInteractionEnabled = YES;
    [self.view addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-37);
        make.width.mas_equalTo(33);
        make.height.mas_equalTo(36);
        make.left.mas_equalTo(26);
    }];
    
    UIButton *backbt = [UIButton buttonWithType:UIButtonTypeCustom];
    [backbt addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [backview addSubview:backbt];
    [backbt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(backview);
    }];
    UIImageView *bluetherview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluether"]];
    bluetherview.userInteractionEnabled = YES;
    [self.view addSubview:bluetherview];
    [bluetherview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.bottom.mas_equalTo(-SafeAreaBottomHeight-52);
        make.height.mas_equalTo(13);
    }];
    
    [self addSelectCorrespondence];
}
-(void)addSelectCorrespondence{
    
    NSArray *viewarray = [[NSArray alloc] init];
    NSArray *namearray = [[NSArray alloc] init];
    if(!XHbluetoolUtils.beginurl){
        viewarray = @[@"update",@"initiallibation"];
        namearray = @[@"APPUpdateone",@"initiallibationname"];
    }else{
        viewarray = @[@"update",@"evaluteus",@"initiallibation"];
        namearray = @[@"APPUpdateone",@"evaluteusname",@"initiallibationname"];
    }
    //    subordinate箭头
//    viewarray = @[@"update",@"evaluteus",@"initiallibation"];
//    namearray = @[@"APPUpdateone",@"evaluteusname",@"initiallibationname"];
    
    for (NSInteger i = 0; i < viewarray.count; i ++) {
        
        UIImageView *checkbox =[[UIImageView alloc] init];
        if([themeColors isEqualToString:@"default"]){
            checkbox.image = [UIImage imageNamed:@"checkbox"];
            
        }else{
            checkbox.backgroundColor = midnightRGB;
            checkbox.layer.cornerRadius = 8;
            checkbox.layer.masksToBounds = YES;
        }
        
        checkbox.userInteractionEnabled = YES;
        checkbox.frame = CGRectMake((winWidth-315)/2, 307.67+kNavHeight+i*(25.67+47), 315, 47);
        [self.view addSubview:checkbox];
        
        UIButton *checkboxbt = [UIButton buttonWithType:UIButtonTypeCustom];
        checkboxbt.frame = CGRectMake(0, 0, 315, 47);
        checkboxbt.tag = i;
        [checkboxbt addTarget:self action:@selector(selectCorrespondence:) forControlEvents:UIControlEventTouchUpInside];
        [checkbox addSubview:checkboxbt];
        
//        UIImageView *subordinate = [[UIImageView alloc] init];
//        subordinate.frame = CGRectMake(315-36, 12.6, 20.33, 20.33);
//        subordinate.image = [UIImage imageNamed:@"network"];
//        [checkbox addSubview:subordinate];
        
        UIImageView *arrayview = [[UIImageView alloc] init];
        arrayview.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",viewarray[i]]];
        
        UIImageView *name = [[UIImageView alloc] init];
        name.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",namearray[i]]];
        
        switch (i) {
            case 0:
                arrayview.frame = CGRectMake(19, 13, 18.33, 20.33);
                name.frame = CGRectMake(19+18.33+14, 14.3, 126.33, 21.33);
                break;
            case 1:
                arrayview.frame = CGRectMake(19, 13, 20.33, 20.33);
                name.frame = CGRectMake(19+20.33+14, 14.3, 137.33, 17.33);
                break;
            case 2:
                arrayview.frame = CGRectMake(19, 13, 19, 20.33);
                name.frame = CGRectMake(19+20.67+14, 14.3, 173.33, 17.33);
                break;
                
            default:
                break;
                
        }
        [checkbox addSubview:name];
        [checkbox addSubview:arrayview];
    }
    
    
    
}
-(void)selectCorrespondence:(UIButton *)button{
  
        
    if(!XHbluetoolUtils.beginurl){
        switch (button.tag) {
            case 0:
                NSLog(@"点击了更新app按钮，目前还没上架");
                [self update];
                break;
            case 1:
               
                [self hint];
                break;

            default:
                break;
        }
    }else{
        switch (button.tag) {
            case 0:
                NSLog(@"点击了更新app按钮，目前还没上架");
                [self update];
                break;
            case 1:
                NSLog(@"点击了评价app按钮，目前还没上架");
                [self evaluateus];
                break;
            case 2:
                [self hint];
                break;
                
            default:
                break;
        }
    }
    
}
- (void)hint{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"Are you sure you want to delete  all information and initialize？" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        [self installAppWithModel:model];
        NSLog(@"点击了yes");
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVc addAction:sureAction];
    [alertVc addAction:cancelAction];
    [self presentViewController:alertVc animated:YES completion:nil];

}
- (void)update{
    
//    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"It's the latest version" message:@"" preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
////        [self installAppWithModel:model];
//        NSLog(@"点击了yes");
//    }];
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//
//    }];
//    [alertVc addAction:sureAction];
//    [alertVc addAction:cancelAction];
//    [self presentViewController:alertVc animated:YES completion:nil];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://apps.apple.com/us/app/bluether/id6469992349"]];
    

}

- (void)evaluateus{
    
//    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"Functionality under development" message:@"" preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
////        [self installAppWithModel:model];
//        NSLog(@"点击了yes");
//    }];
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//
//    }];
//    [alertVc addAction:sureAction];
//    [alertVc addAction:cancelAction];
//    [self presentViewController:alertVc animated:YES completion:nil];
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://apps.apple.com/us/app/bluether/id6469992349"]];

}

-(void)back{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
